package cn.com.sparkle.paxos.net.netlayer;

import java.util.HashMap;

import cn.com.sparkle.paxos.checksum.ChecksumUtil;
import cn.com.sparkle.paxos.net.frame.FrameBody;

public abstract class PaxosSession {
	private HashMap<AttributeKey<?>, Object> attachment = new HashMap<AttributeKey<?>, Object>();

	private int checksumType = ChecksumUtil.PURE_JAVA_CRC32;

	@SuppressWarnings("unchecked")
	public <T> T get(AttributeKey<T> key) {
		return (T) attachment.get(key);
	}

	public void put(AttributeKey<?> key, Object obj) {
		attachment.put(key, obj);
	}

	public int getChecksumType() {
		return checksumType;
	}

	public void setChecksumType(int checksumType) {
		this.checksumType = checksumType;
	}

	public abstract void write(FrameBody message) throws NetCloseException;

	public abstract void closeSession();

}
